import React, {useEffect} from 'react';
import { useSelector, useDispatch } from 'react-redux';

import Layout from '@components/home/layout';
import PageTitle from '@components/home/page-title'
import NewsList from '@components/home/news/news-list'
import Pagination from '@components/home/pagination'

import { HomeActionTypes } from '@actions/index'

// @connect((state) => ({state})) // @connect 装饰器只能装饰类组件，使用useSelector替代
export default ({ newsList = new Array(10).fill({
  id:Math.round(Math.random()*100000),
  title:'2017首届智享UNI创新创业大赛京津冀赛区北京复赛成功决出前三名',
  pic:'http://www.wiste.cn/Public/Uploads/20180117/5a5e81c4aa566.jpg',
  date:'2020-01-30',
}) }) => {
  
  const dispach = useDispatch();
  
  // const homeData = useSelector(state=>state.home)
  // const picList = [
  //   {
  //     index:0,
  //     src:'http://www.wiste.cn/Public/Uploads/20170816/599430b3ba5f9.jpg'
  //   },
  //   {
  //     index:1,
  //     src:'http://www.wiste.cn/Public/Uploads/20170816/599430b3ba5f9.jpg'
  //   },
  // ]
  // console.log(homeData)

  useEffect(() => {
    dispach({
      type:HomeActionTypes.HOME_PAGE_DATA
    });
  }, []);

  return (
    <Layout>
      <PageTitle title={'最新资讯'} titleEn={'Latest News'}/>
      <NewsList newsList={newsList}/>
      <Pagination/>
    </Layout>
  );
};
